<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Client Flow Example</title>
	</head>
	<body>
		<div id="fb-root"></div>
		<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
		<script src="http://connect.facebook.net/en_US/all.js"></script>
		<script type="text/javascript">
			FB.init({
				appId:'209476492413696', cookie:true, status:true, xfbml:true 
			});

			function checkFacebook() {
				/* FB.getLoginStatus Session Object
					{
					    status: 'connected',
					    session: {
					        access_token: '...',
					        expires:'...',
					        secret:'...',
					        session_key:'...',
					        sig:'...',
					        uid:'...'
					    }
					}
				*/
				FB.getLoginStatus(function(response) {
					if (response.session) {
						// logged in and connected user, someone you know
						document.getElementById("accessToken").value = response.session.access_token;
					} else {
						// no user session available, someone you dont know
						FB.login(function (response) {  // 페이스북 로그인 창을 띄웁니다.
							if (response.session) {
								// 로그인 상태로 판정될 때 실행되는 코드
								document.getElementById("accessToken").value = response.session.access_token;
							} else {
							// 로그아웃 상태로 판정될 때 실행되는 코드
							}
						}, { perms: 'email, user_checkins, publish_stream' });
					}
				});
			}		
		</script>
		<form method="post" action="/writeProcess.do">
			<input type="text" id="accessToken" name="accessToken" value="" /><br/>
			<input type="checkbox" id="faceBook" name="facebook" value="" onclick="javascript:checkFacebook();" />FaceBook
			<textarea id="feed" name="feed" cols="100" rows="10"></textarea>
			<br/>
			<input type="submit" value="WRITE" />
		</form>
	</body>
</html>